package com.hualan.controller;


import com.hualan.pojo.CourseSort;
import com.hualan.pojo.PageResult;
import com.hualan.pojo.Result;
import com.hualan.service.CourseSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseSort")
public class CourseSortController {

    @Autowired
    private CourseSortService courseSortService;

    @GetMapping
    public Result queryAllCourseSort(
            String categoryName,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize
    ){
        PageResult pageResult= courseSortService.queryAllCourseSort(categoryName, page, pageSize);
        return Result.success(pageResult);
    }
    @DeleteMapping
    public Result deleteCourseSort(@RequestParam List<Integer> ids){
        courseSortService.deleteCourseSort(ids);
        return Result.success();
    }

    @PostMapping
    public Result saveCourseSort(@RequestBody CourseSort courseSort){
        courseSortService.saveCourseSort(courseSort);
        return Result.success();
    }

    @PutMapping
    public Result updateCourseSort(@RequestBody CourseSort courseSort){
        courseSortService.updateCourseSort(courseSort);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getCourseSortById(@PathVariable Integer id){
        CourseSort courseSort= courseSortService.getCourseSortById(id);
        return Result.success(courseSort);
    }

}
